//获取地址栏中的categoryId参数
var postId = getUrlParams('id');
var review;
//根据id获取文章详情
$.ajax({
    type:'get',
    url:'/posts/'+postId,
    success:function(response){
        var html = template('detailTpl',response);
        $('#detailBox').html(html);
    }
});

$('#detailBox').on('click','#like',function(){
    $.ajax({
        type:'post',
        url:'/posts/fabulous/'+postId,
        success:function(){
            alert('点赞成功，感谢您的支持');
        }
    });
})

//获取网站配置信息
$.ajax({
    type:'get',
    url:'/settings',
    success:function(response){
        review = response.review;
        if(response.comment){
           var html = template('commentTpl');
           $('#commentBox').html(html);
        }
    }
});

//使用事件委托事件提交评论
$('#commentBox').on('submit','form',function(){
    var content = $(this).find('textarea').val();
    var state;
    if(review){
        //要经过人工审核
        state = 0;
    }else{
        //不需要人工审核
        state = 1;
    }
    $.ajax({
        type:'post',
        url:'/comments',
        data:{
            content:content,
            post:postId,
            state:state
        },
        success:function(response){
            location.reload();
        },
        error:function(){
            alert('评论失败');
        }

    });
    return false;
})